Skip to content

Add unique prefix - increasing counter #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MML-coder
Copy link
Collaborator

The SyntheticTextItemsGenerator was generating prompts that could trigger vLLM's automatic prefix caching, leading to hitting the prefix cache up to 80% in some cases during the performance benchmarking.

Implemented unique prefix injection to guarantee 0% prefix cache hit rate while maintaining realistic prompt characteristics.

Test:
Performing some tests on the H200 target accelerator to confirm the fix.

@MML-coder MML-coder marked this pull request as ready for review July 8, 2025 18:58
@MML-coder
Copy link
Collaborator Author

I am trying to figure out lint errors. When i run it locally they all seemed to have passed. :)

ruff check --fix tests/unit/dataset/test_synthetic.py
All checks passed!

@MML-coder
Copy link
Collaborator Author

End to end test:

Ran following command for inference server running llama

command:
`
guidellm benchmark --target 'http://llama-4-maverick-fp8-c94dbf44-predictor.kserve-e2e-perf.svc.cluster.local:8080/v1' --model RedHatAI/Llama-4-Maverick-17B-128E-Instruct-FP8 --processor RedHatAI/Llama-4-Maverick-17B-128E-Instruct-FP8 --data='{"prompt_tokens":512 ,"prompt_tokens_stdev":128,"prompt_tokens_min":1,"prompt_tokens_max":1024,"output_tokens":2048,"output_tokens_stdev":64,"output_tokens_min":1,"output_tokens_max":4096}' --rate-type concurrent --rate "100" --warmup-percent 0.2 --max-requests 500 --output-path output.json

`

VLLM output:
INFO 07-08 17:56:44 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1809.3 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 6.5%, Prefix cache hit rate: 0.0% INFO 07-08 17:56:54 [loggers.py:116] Engine 000: Avg prompt throughput: 121.7 tokens/s, Avg generation throughput: 1689.8 tokens/s, Running: 99 reqs, Waiting: 0 reqs, GPU KV cache usage: 6.7%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:04 [loggers.py:116] Engine 000: Avg prompt throughput: 1136.3 tokens/s, Avg generation throughput: 1267.3 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 5.9%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:14 [loggers.py:116] Engine 000: Avg prompt throughput: 1584.5 tokens/s, Avg generation throughput: 1106.8 tokens/s, Running: 99 reqs, Waiting: 0 reqs, GPU KV cache usage: 4.2%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:24 [loggers.py:116] Engine 000: Avg prompt throughput: 1471.5 tokens/s, Avg generation throughput: 1096.7 tokens/s, Running: 98 reqs, Waiting: 0 reqs, GPU KV cache usage: 2.5%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:34 [loggers.py:116] Engine 000: Avg prompt throughput: 611.2 tokens/s, Avg generation throughput: 1518.6 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 2.4%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:44 [loggers.py:116] Engine 000: Avg prompt throughput: 52.7 tokens/s, Avg generation throughput: 1629.9 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 2.8%, Prefix cache hit rate: 0.0% INFO 07-08 17:57:54 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1759.5 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 3.3%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:04 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1769.4 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 3.9%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:14 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1769.2 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 4.4%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:24 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1789.4 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 4.9%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:34 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1799.9 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 5.4%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:44 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1839.6 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 6.0%, Prefix cache hit rate: 0.0% INFO 07-08 17:58:54 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1829.2 tokens/s, Running: 100 reqs, Waiting: 0 reqs, GPU KV cache usage: 6.5%, Prefix cache hit rate: 0.0% INFO 07-08 17:59:04 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1724.9 tokens/s, Running: 92 reqs, Waiting: 0 reqs, GPU KV cache usage: 6.4%, Prefix cache hit rate: 0.0% INFO 07-08 17:59:14 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 1309.3 tokens/s, Running: 46 reqs, Waiting: 0 reqs, GPU KV cache usage: 3.3%, Prefix cache hit rate: 0.0% INFO 07-08 17:59:24 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 426.8 tokens/s, Running: 4 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.3%, Prefix cache hit rate: 0.0% INFO 07-08 17:59:34 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 19.2 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 0.0% INFO 07-08 17:59:44 [loggers.py:116] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 0.0%

📦 Build Artifacts Available
The build artifacts (.whl and .tar.gz) have been successfully generated and are available for download: https://github.com/neuralmagic/guidellm/actions/runs/16178342451/artifacts/3498543434.
They will be retained for up to 30 days.

@MML-coder
Copy link
Collaborator Author

pre-commit run --all-files trim trailing whitespace.................................................Passed fix end of files.........................................................Passed run linter...............................................................Passed run formatter............................................................Passed mypy.....................................................................Passed

if prompt_tokens <= 0:
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt_tokens should never be less than 1. This is either redundant or there is an error in the sampling code.

Comment on lines +178 to +206
"prompt": self._create_prompt(
prompt_tokens, start_index, self.request_counter
),
"prompt_tokens_count": prompt_tokens,
"output_tokens_count": output_tokens,
}

def _create_prompt(self, prompt_tokens: int, start_index: int) -> str:
def _create_prompt(
self, prompt_tokens: int, start_index: int, request_id: int
) -> str:
"""
Create a prompt with unique prefix to prevent vLLM prefix caching.
Args:
prompt_tokens: Target number of tokens for the prompt
start_index: Starting position in the text corpus
request_id: Unique identifier for this request (used as prefix)
Returns:
Generated prompt string with unique prefix
"""
if prompt_tokens <= 0:
return ""
return f"{request_id}: "

unique_prefix = f"{request_id}: "

# Calculate how many tokens the prefix uses
prefix_tokens = len(self.processor.tokenize(unique_prefix))

# Adjust target tokens to account for the prefix
remaining_tokens = max(1, prompt_tokens - prefix_tokens)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how unique_prefix is an arbitrary number of tokens. If prompt_tokens is too low some or all requests will have len(unique_prefix) > len(prefix_tokens). It would be better if we make the prefix length always one token. Easy way to do this is iterate over the tokenizer vocab. Something like:

prefix_iter = iter(t for t in self.processor.get_vocab())
...
unique_prefix = next(it)

Comment on lines +131 to +140
def test_validation_positive_values(self):
"""Test that negative values are rejected."""
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=-1, output_tokens=20)

with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=-1)

with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=10, samples=-1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong bounds

Suggested change
def test_validation_positive_values(self):
"""Test that negative values are rejected."""
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=-1, output_tokens=20)
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=-1)
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=10, samples=-1)
def test_validation_nonpositive_values(self):
"""Test that non-positive values are rejected."""
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=0, output_tokens=20)
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=0)
with pytest.raises(ValueError):
SyntheticDatasetConfig(prompt_tokens=20, output_tokens=10, samples=0)

@pytest.fixture
def tokenizer(self):
"""Fixture to provide a tokenizer for testing."""
tokenizer = AutoTokenizer.from_pretrained("gpt2")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tokenizer need to be mocked; unit tests should not need to download data to function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants